<?php
    class Admincp_Model_Common
    {
        public function cut_string($str,$len,$more) {
            if ($str=='' || $str==NULL) return $str;
            if (is_array($str)) return $str;
            $str = trim($str);
            if (strlen($str) <= $len) return $str;
            $str = substr($str,0,$len);
            if ($str != '') {
                if (!substr_count($str," ")) {
                    if ($more) $str .= " ...";
                    return $str;
                }
                while(strlen($str) && ($str[strlen($str)-1] != " ")) $str = substr($str,0,-1);
                $str = substr($str,0,-1);
                if ($more) $str .= " ...";
            }
            return $str;
        }

        public function formatDate($inputDate) {
            $str = explode('-', $inputDate);
            $outputDate = $str[2].'-'.$str[1].'-'.$str[0];
            return $outputDate;
        }
        
        public function formatDateSite($inputDate) {
            $str = explode('-', $inputDate);
            $outputDate = $str[2].'/'.$str[1].'/'.$str[0];
            return $outputDate;
        }
        
        public function formatMoney($number, $fractional=false) {
			if ($fractional) {
				$number = sprintf('%f', $number);
			}
			while (true) {
				$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1.$2', $number);
				if ($replaced != $number) {
					$number = $replaced;
				} else {
					break;
				}
			}
			return $number;
		}
    }
